1. Field of the Invention
This invention relates in general to the field of instruction execution in computers, and more specifically to an improved method and apparatus for executing an exchange instruction within a microprocessor.
2. Description of the Related Art
Within an instruction set for a processing system, a common instruction that is provided is an exchange instruction. The exchange instruction allows a programmer to specify within a single instruction, two operands that are to be swapped. This can be illustrated with the mnemonic XCHG R1, R2. More specifically, this instruction specifies that the contents of a register R1 are to be written into a register R2, and that the contents of the register R2 are to be written into the register R1.
Even though a single instruction allows a programmer to specify the two operand locations that are to be swapped, known microprocessors do not move both of the operands into switched locations at the same time. Rather, the first operand R1 is stored into a temporary location to preserve the contents of R1 while the contents of R2 are being written into R1. Following the retrieval of R2, and subsequent writing of the contents of R2 into R1, the microprocessor retrieves the preserved contents of R1, located in the temporary location, and writes them into R2.
The time required to first store the operand specified by R1 into a temporary location, and later retrieve this operand for storage into R2 is time consuming for the microprocessor. For example, an exchange instruction within an Intel.RTM. x86 microprocessor typically requires at least 3 clock cycles to perform a register to register operand swap. The first clock is required to store the first operand into a temporary location. The second clock retrieves the second operand and stores it into the first location. The third clock retrieves the first operand from the temporary location and stores it into the second location.
If multiple exchange instructions are used within a particular program, the time delay required for executing the exchange instructions, as described above, can significantly affect the time required to execute the program.
Therefore, what is needed is an apparatus and method that allows an exchange operation to be executed faster than has heretofore been provided. In addition what is needed is a microprocessor that executes an exchange instruction without requiring an operand to be stored into a temporary location.